package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;

import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.thread.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.dto.ReservationPageDto;
import com.zzyl.nursing.dto.WechatNursingProjectDto;
import com.zzyl.nursing.service.IMemberReservationService;
import com.zzyl.nursing.vo.ReservationVo;
import com.zzyl.serve.domain.NursingProject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@Slf4j
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{


    @Autowired
    private IMemberReservationService memberReservationService;


    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        Integer count = memberReservationService.getCancelledReservationCount(userId);
        return R.ok(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("根据时间查询取消预约数量")
    public AjaxResult countByTime(Long time) {
        List<Map<String, Object>> list = memberReservationService.countByTime(time);
        return success(list);
    }




    @PostMapping
    @ApiOperation("新增预约")
    public AjaxResult insertReservationInfo(@RequestBody ReservationDto dto) {

        memberReservationService.insertReservationInfo(dto);
        return success("success,操作成功");
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public  AjaxResult getReservationList(ReservationPageDto dto)
    {
        startPage();
        List<ReservationVo> list = memberReservationService.getReservationList(dto);
        TableDataInfo result = getDataTable(list);
        return success(result);

    }

    //todo
    @PutMapping("/{id}/cancel")
    @ApiOperation("修改预约--取消预约")
    public AjaxResult updateReservationInfo(@PathVariable Long id) {
        memberReservationService.updateReservationInfo(id);
        log.info("修改预约成功，预约id为：{}",id);
        return success("success,操作修改预约成功");
    }



}